#ifndef SAFESTACK_H_
#define SAFESTACK_H_

#include <stack>

#include "Common\stragy\threadsafe\CriticalLock.h"
#include "Common\stragy\threadsafe\Guard.h"

namespace FURY
{
	namespace CONTAINER
	{
		using FURY::STRAGY::CriticalLock;
		using FURY::STRAGY::Guard;

		template<typename T>
		class SafeStack
		{
			typedef std::stack<T>	StackContainer;
			StackContainer	m_container;
			CriticalLock	m_lock;
		public:
			SafeStack(void)	{};
			~SafeStack(void)	{};

		public:
			void Push(T obj)
			{
				Guard<CriticalLock> guard(m_lock);
				m_container.push(obj);
			};

			T Pop(void)
			{
				Guard<CriticalLock> guard(m_lock);
				T obj = m_container.top();
				m_container.pop();
				return obj;
			};

			bool Empty(void)
			{
				return m_container.empty();
			};

			int Size(void)
			{
				return m_container.size();
			};

			void Clear(void)
			{
				Guard<CriticalLock> guard(m_lock);
				while (!m_container.empty())
					m_container.pop();
			};
		};
	};
};

#endif	//	SAFESTACK_H_